﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Sale_Common;
using Sale_Model;
using Sale_Operation;
using ExtAspNet;
namespace SaleSystem.Other
{
    public partial class SysUserEdit : PageBase
    {
        #region Page Event
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Id = ValueHandler.GetIntNumberValue(Request["Id"]);
                bnClose.OnClientClick = ExtAspNet.ActiveWindow.GetHideReference();
                GetAndBind();
            }
        }
        protected void bnSave_Click(object sender, EventArgs e)
        {
            SModel.SUser_Id = Id;
            SModel.SUser_Name = this.tb_SUser_Name.Text;
            SModel.SUser_Pwd = this.tb_SUser_Pwd.Text;
            SModel.CreateMan = LinkService.GetCurrentUser().SUser_Id;
            SModel.CreateTime = System.DateTime.Now;
            SModel.State = 0;          
            bool blHasExists = Manager.HasExistsUserName(SModel);
            if (blHasExists)
            {
                ExtAspNet.Alert.Show("用户名已经存在，请重新输入！", MessageBoxIcon.Information);
            }
            else
            {
                bool blRes =Manager.Save(SModel);
                if (blRes)
                    PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
                else
                    ExtAspNet.Alert.Show("用户编辑失败！", MessageBoxIcon.Error);
            }
            
        }
        #endregion
        #region Method
        private void GetAndBind()
        {
            if (Id != 0)
            {
                dtList = Manager.GetList("SUser_Id="+Id);
                if (dtList.Rows.Count > 0)
                {
                    this.tb_SUser_Name.Text = ValueHandler.GetStringValue(dtList.Rows[0]["SUser_Name"]);
                    this.tb_SUser_Pwd.Text = ValueHandler.GetStringValue(dtList.Rows[0]["SUser_Pwd"]);
                }
            }
        }
        #endregion

        #region Property
        SysUsersOp Manager = new SysUsersOp();
        SysUser SModel = new SysUser();
        #endregion
    }
}
